package com.muyu.user.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.DataPageResp;
import com.muyu.common.core.web.page.PageQueryModel;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.user.domain.SysUser;
import com.muyu.user.domain.req.*;
import com.muyu.user.domain.resp.SysUserPageResp;
import com.muyu.user.service.SysUserManageService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户管理
 *
 * @author <a href="mailto:1416681852@qq.com">liuguoqiang</a>
 * @version 1.0
 * @description: 用户管理
 * @date 2025/9/14 22:22
 */
@RestController
@RequestMapping("manage")
public class SysUserManageController extends BaseController {
    /**
     * 用户管理接口
     */

    @Autowired
    private SysUserManageService sysUserManageService;

    /**
     * 用户管理分页列表
     */
    @Operation(summary = "获取用户管理列表", description = "获取用户管理列表")
    @PostMapping("userMangeList")
    @RequiresPermissions("user:manage:userMangeList")
    public Result<DataPageResp<SysUserPageResp>> userMangeList(@RequestBody SysUserPageReq sysUserPageReq) {
        // 调用服务层获取分页数据
        PageQueryModel<SysUserPageResp> pageQueryModel = sysUserManageService.selectUserPageList(sysUserPageReq);
        // 返回分页结果
        return resultList(pageQueryModel);
    }
    /**
     * 给用户批量设置标签
     */
    @Operation(summary = "给用户批量设置标签", description = "给用户批量设置标签")
    @PostMapping("setUserPlTag")
    @RequiresPermissions("user:manage:setUserPlTag")
    public Result setUserPlTag(@RequestBody BatchSetTagsReq batchSetTagsReq){
        sysUserManageService.SetUserPlTag(batchSetTagsReq);
        return Result.success();
    }
    /**
     * 给用户批量设置分组
     */
    @Operation(summary = "给用户批量设置分组", description = "给用户批量设置分组")
    @PostMapping("setUserPlGroup")
    @RequiresPermissions("user:manage:setUserPlGroup")
    public Result setUserPlGroup(@RequestBody BatchSetGroupReq batchSetGroupReq){
        sysUserManageService.setUserPlGroup(batchSetGroupReq);
        return Result.success();
    }
    /**
     * 用户详情
     */
    @Operation(summary = "用户详情", description = "用户详情")
    @GetMapping("detail/{userId}")
    public Result<SysUser> getUserDetail(@PathVariable("userId") Integer userId){
        return Result.success(sysUserManageService.getUserDetail(userId));
    }
    /**
     * 设置用户等级
     */
    @Operation(summary = "设置用户等级", description = "设置用户等级")
    @PostMapping("setUserLevel")
    public Result setUserLevel(@RequestBody @Valid SysUserSetLevelReq sysUserSetLevelReq){
        sysUserManageService.setUserLevel(sysUserSetLevelReq);
        return Result.success();
    }
    /**
     * 编辑用户
     */
    @Operation(summary = "编辑用户", description = "编辑用户")
    @PutMapping("setUserUpd")
    public Result setUserUpd(@RequestBody @Valid SysUserUpdReq sysUserUpdReq){
        sysUserManageService.setUserUpd(sysUserUpdReq);
        return Result.success();
    }
}
